package error

func totalHammingDistance(nums []int) int {
	result := 0
	countHammingDistance := func(a, b int) int {
		result := 0
		xor := a ^ b
		for xor > 0 {
			result += xor & 1
			xor >>= 1
		}
		return result
	}

	for i := 0; i < len(nums); i++ {
		for j := i + 1; j < len(nums); j++ {
			result += countHammingDistance(nums[i], nums[j])
		}
	}
	return result
}
